package main;

/**
 * Creates byte arrays for messages
 * @author Mark van der Wal
 *
 */
public class ProtocolEncoder 
{
	static public byte[] EncodeTurn(byte value)
	{
		// create buffer
		byte[] buffer = new byte[2];
		
		// put the opcode in
		buffer[0] = (byte) ProtocolOpcodes.T_TURN.Opcode();
		buffer[1] = value;
		
		return buffer;
	}
	
	static public byte[] EncodeDrive(byte value)
	{
		// create buffer
		byte[] buffer = new byte[2];
		
		// put the opcode in
		buffer[0] = (byte) ProtocolOpcodes.T_DRIVE.Opcode();
		buffer[1] = value;
		
		return buffer;
	}
	
	static public byte[] EncodeCommand(byte value)
	{
		// create buffer
		byte[] buffer = new byte[2];
		
		// put the opcode in
		buffer[0] = (byte) ProtocolOpcodes.T_COMMAND.Opcode();
		buffer[1] = value;
		
		return buffer;
	}
        
        static public byte[] EncodeHelling(byte value)
	{
		// create buffer
		byte[] buffer = new byte[2];
		
		// put the opcode in
		buffer[0] = (byte) ProtocolOpcodes.V_HELLING.Opcode();
		buffer[1] = value;
		
		return buffer;
	}
                
        static public byte[] EncodeAccu(byte value)
	{
		// create buffer
		byte[] buffer = new byte[2];
		
		// put the opcode in
		buffer[0] = (byte) ProtocolOpcodes.V_ACCU.Opcode();
		buffer[1] = value;
		
		return buffer;
	}
                        
        static public byte[] EncodeMotor(byte value)
	{
		// create buffer
		byte[] buffer = new byte[2];
		
		// put the opcode in
		buffer[0] = (byte) ProtocolOpcodes.V_MOTOR.Opcode();
		buffer[1] = value;
		
		return buffer;
	}
                                
        static public byte[] EncodeMaze(byte value1, byte value2, byte value3)
	{
		// create buffer
		byte[] buffer = new byte[4];
		
		// put the opcode in
		buffer[0] = (byte) ProtocolOpcodes.V_MAZE_SENSOR.Opcode();
		buffer[1] = value1;
                buffer[2] = value2;
                buffer[3] = value3;
		
		return buffer;
	}
        
        static public byte[] EncodeSensors(byte value1, byte value2, byte value3, byte value4, byte value5, byte value6)
	{
		// create buffer
		byte[] buffer = new byte[7];
		
		// put the opcode in
		buffer[0] = (byte) ProtocolOpcodes.V_SENSOR.Opcode();
		buffer[1] = value1;
                buffer[2] = value2;
                buffer[3] = value3;
                buffer[4] = value4;
                buffer[5] = value5;
                buffer[6] = value6;
		
		return buffer;
	}
}
